package com.vken.blog.action;

import java.util.List;
import com.opensymphony.xwork2.ActionSupport;
import com.vken.blog.model.Link;
import com.vken.blog.service.LinkManager;
import com.vken.blog.util.Const;

public class LinkAction extends ActionSupport {
	private static final long serialVersionUID = -2693208424295320401L;
	private Integer id;
	private Link link;
	private List<Link> links;
	private LinkManager linkManager;

	public void setLinkManager(LinkManager linkManager) {
		this.linkManager = linkManager;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public Link getLink() {
		return link;
	}

	public void setLink(Link link) {
		this.link = link;
	}

	public List<Link> getLinks() {
		return links;
	}

	public String add() {
		linkManager.insert(link, Const.BLOG_ID);
		return SUCCESS;
	}

	public String load() {
		if (id == null) {
			return INPUT;
		}
		link = linkManager.get(id);
		return SUCCESS;
	}

	public String delete() {
		if (id != null) {
			linkManager.delete(id);
		}
		return SUCCESS;
	}

	public String update() {
		linkManager.update(link);
		return SUCCESS;
	}

	public String list() {
		links = linkManager.list(Const.BLOG_ID);
		return SUCCESS;
	}
}
